<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
	<th:block th:include="include :: header('修改客户订单')" />
	<th:block th:include="include :: datetimepicker-css" />
	<th:block th:include="include :: bootstrap-editable-css" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-order-edit" th:object="${crmOrder}">
			<h4 class="form-header h4">基本信息</h4>
			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label">主题：</label>
						<div class="col-sm-8">
							<div class="form-control-static" th:text="${crmOrder.orderName}"></div>
						</div>
					</div>
				</div>
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label">成交客户：</label>
						<div class="col-sm-8">
							<div class="form-control-static" th:text="${crmOrder.customer.customerName}"></div>
						</div>
					</div>
				</div>
			</div>
			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">
						<label class="col-sm-4 control-label">成交总额：</label>
						<div class="col-sm-8">
							<div class="form-control-static" th:text="${crmOrder.totalPrice}"></div>
						</div>
					</div>
				</div>
				<div class="col-sm-6">
					<div class="form-group">    
		                <label class="col-sm-4 control-label">总成本：</label>
		                <div class="col-sm-8">
		                    <div class="form-control-static" th:text="${crmOrder.costPrice}"></div>
		                </div>
		            </div>
				</div>
			</div>			
			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">    
		                <label class="col-sm-4 control-label">成交/签约时间：</label>
		                <div class="col-sm-8">
		                    <div class="form-control-static" th:text="${#dates.format(crmOrder.orderDate, 'yyyy-MM-dd')}" ></div>
		                </div>
		            </div>
				</div>
				<div class="col-sm-6">
					<div class="form-group">    
		                <label class="col-sm-4 control-label">付款方式：</label>             
		                <div class="col-sm-8">
							<div class="form-control-static" th:text="${@dict.getLabel('pay_type', crmOrder.payType)}"></div>
						</div>
		            </div>
				</div>
			</div>			
			<div class="row">
				<div class="col-sm-6">
					<div class="form-group">    
		                <label class="col-sm-4 control-label">有效期开始时间：</label>
		                <div class="col-sm-8">
		                    <div class="form-control-static" th:text="${#dates.format(crmOrder.validStart, 'yyyy-MM-dd')}" ></div>
		                </div>
		            </div>
				</div>
				<div class="col-sm-6">
					<div class="form-group">    
		                <label class="col-sm-4 control-label">有效期结束时间：</label>
		                <div class="col-sm-8">
		                    <div class="form-control-static" th:text="${#dates.format(crmOrder.validEnd, 'yyyy-MM-dd')}" ></div>
		                </div>
		            </div>
				</div>
			</div>
			
			<div class="row">
				<div class="col-sm-6">
					 <div class="form-group">    
		                <label class="col-sm-4 control-label">付款状态：</label>
		                <div class="col-sm-8">
							<div class="form-control-static" th:text="${@dict.getLabel('order_status', crmOrder.orderStatus)}"></div>
						</div>
		            </div>
				</div>
				<div class="col-sm-6">
					 <div class="form-group">    
		                <label class="col-sm-4 control-label">出库状态：</label>
		                <div class="col-sm-8">
							<div class="form-control-static" th:text="${@dict.getLabel('order_out_status', crmOrder.orderOutStatus)}"></div>
						</div>
		            </div>
				</div>
			</div>				
			<div class="row">
				<div class="col-sm-12">
					<div class="form-group">
						<label class="col-xs-2 control-label">备注：</label>
						<div class="col-xs-10">
							<div class="form-control-static" th:text="${crmOrder.remark}"></div>
						</div>
					</div>
				</div>
			</div>
		</form>
		<h4 class="form-header h4">产品信息</h4>
		<div class="container-div">
			<div class="row">
				<div class="col-sm-12 select-table table-striped">
					<table id="bootstrap-table"></table>
				</div>
			</div>
		</div>
	</div>
	<th:block th:include="include :: footer" />
	<th:block th:include="include :: datetimepicker-js" />
	<th:block th:include="include :: bootstrap-table-editable-js" />
	<script th:inline="javascript">
		var productCategoryDatas = [[${@dict.getType('product_category')}]];
		var orderProductStatusDatas = [[${@dict.getType('order_product_status')}]];
		var prefix = ctx + "crm/order";
		var prefixProduct = ctx + "crm/product";
		var prefixOrderProduct =  ctx + "crm/orderProduct";
		var orderId=[[${orderId}]];
		
		$("#form-order-edit").validate({
			focusCleanup : true
		});
		
		$(function() {
            var options = {
                url: prefixOrderProduct + "/listAll",
                removeUrl: prefixOrderProduct + "/remove",
                pagination: false,
		        showSearch: false,
                showRefresh: false,
                showToggle: false,
                showColumns: false,
                modalName: "关联产品信息",
                queryParams : {
                    orderId:orderId
				},
                columns: [
                {
                    field : 'orderProductId', 
                    title : '订单产品ID',
                    visible: false
                },
		        {
                    title: "序号",
                    formatter: function (value, row, index) {
                 	    return $.table.serialNumber(index);
                    }
                },
                {
                    field : 'orderId', 
                    title : '订单id',
                    visible: false
                },
                {
                    field : 'productId', 
                    title : '产品id',
                    visible: false
                },
                {
                    field : 'productName', 
                    title : '产品名称'
                },
                {
                    field : 'product.incomePrice', 
                    title : '成本'
                },
                {
                    field : 'product.salePrice', 
                    title : '原价'
                },
                {
                    field : 'sellPrice', 
                    title : '销售单价'
                },
                {
                    field : 'productCount', 
                    title : '成交数量'
                },
                {
                    field : 'discount', 
                    title : '折扣'
                },
                {
                    field : 'realPrice', 
                    title : '实际成交价'
                },
				{
				    title: '图片',
				    formatter: function(value, row, index) {
				    	return $.table.imageView(row.product.productImage);
				    }
				},
                {
                    field : 'product.productCategory', 
                    title : '产品类别',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(productCategoryDatas, value);
                    },
		            sortable: true
                },
                {
                    field : 'orderProductStatus', 
                    title : '状态',
                    formatter: function(value, row, index) {
                       return $.table.selectDictLabel(orderProductStatusDatas, value);
                    },
                    visible: false
                }]
            };
            $.table.init(options);
        });		
		
		$("input[name='orderDate']").datetimepicker({
            format: "yyyy-mm-dd",
            minView: "month",
            autoclose: true
        });
        
        $("input[name='validStart']").datetimepicker({
    		format: 'yyyy-mm-dd',
    		minView: "month",
    	    todayBtn:  true,
    	    autoclose: true
    	}).on('changeDate', function(event) {
    		event.preventDefault();
    		event.stopPropagation();
    		var startTime = event.date;
    		$("input[name='validEnd']").datetimepicker('setStartDate', startTime);
    	});
    	
    	$("input[name='validEnd']").datetimepicker({
    		format: 'yyyy-mm-dd',
    		minView: "month",
    		todayBtn:  true,
    		autoclose: true
    	}).on('changeDate', function(event) {
    		event.preventDefault();
    		event.stopPropagation();
    		var endTime = event.date;
    		$("input[name='validStart']").datetimepicker('setEndDate', endTime);
    	});
    	
	</script>
</body>
</html>